using System;
using System.Diagnostics;

namespace Kiwi.Container.Scope
{
    [DebuggerDisplay("{Discriminator}")]
    public class ContainerScope : IContainerScope, IEquatable<IContainerScope>
    {
        public static readonly IContainerScope Container = new ContainerScope("Container");
        public static readonly IContainerScope Global = new ContainerScope("Global");
        public static readonly IContainerScope HttpRequest = new ContainerScope("HttpRequest");
        public static readonly IContainerScope HttpSession = new ContainerScope("HttpSession");
        public static readonly IContainerScope WcfRequest = new ContainerScope("WcfRequest");


        public ContainerScope(object discriminator)
        {
            Discriminator = discriminator;
        }

        #region IContainerScope Members

        public object Discriminator { get; set; }

        #endregion

        #region IEquatable<IContainerScope> Members

        public bool Equals(IContainerScope other)
        {
            if (ReferenceEquals(this, other))
            {
                return true;
            }
            if (other == null)
            {
                return false;
            }
            return Equals(Discriminator, other.Discriminator);
        }

        #endregion

        public override bool Equals(object obj)
        {
            return Equals(obj as IContainerScope);
        }

        public override int GetHashCode()
        {
            return Discriminator == null ? 0 : Discriminator.GetHashCode();
        }
    }
}